<?php

    include('./library/conn.php');

    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];

    $insert = "INSERT INTO `users` ( `password`, `username`) VALUES ( '$password', '$username');";

    $select = "select * from users where username='$username'";

    $result2 = $mysqli->query($select);

    

    if($result2->num_rows>0){
        echo '<script>alert("用户名已存在");</script>';
        echo '<script>location.href="../src/regist.html";</script>';
    }else{
        $result = $mysqli->query($insert);
        echo '<script>alert("注册成功");</script>';
        echo '<script>location.href="../src/index.html";</script>';
    }
    $mysqli->close();
?>